package cn.aran.basic.service.impl;

import cn.aran.basic.mapper.BaseMapper;
import cn.aran.basic.query.BaseQuery;
import cn.aran.basic.service.IBaseService;
import cn.aran.basic.utils.PageList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class BaseServiceImpl<T> implements IBaseService<T> {
    @Autowired
    private BaseMapper<T> baseMapper;

    /*
     * @Title: loadAll
     * @Description: 查询全部
     * @Author: Aran
     * @Version: 1.0
     * @Date:  2022/6/26 14:53
     * @Parameters: []
     * @Return java.util.List<cn.aran.org.domain.T>
     */
    @Override
    public List<T> loadAll() {
        return baseMapper.loadAll();
    }

    /*
     * @Title: loadById
     * @Description: 根据id查询
     * @Author: Aran
     * @Version: 1.0
     * @Date:  2022/6/26 14:53
     * @Parameters: [id]
     * @Return cn.aran.org.domain.T
     */
    @Override
    public T loadById(Long id) {
        return baseMapper.loadById(id);
    }

    /*
     * @Title: remove
     * @Description: 删除
     * @Author: Aran
     * @Version: 1.0
     * @Date:  2022/6/26 14:54
     * @Parameters: [id]
     * @Return void
     */
    @Transactional
    @Override
    public void remove(Long id) {
        baseMapper.remove(id);
    }

    /*
     * @Title: save
     * @Description: 新增
     * @Author: Aran
     * @Version: 1.0
     * @Date:  2022/6/26 14:54
     * @Parameters: [t]
     * @Return void
     */
    @Transactional
    @Override
    public void save(T t) {
        baseMapper.save(t);
    }

    /*
     * @Title: update
     * @Description: 修改
     * @Author: Aran
     * @Version: 1.0
     * @Date:  2022/6/26 14:54
     * @Parameters: [t]
     * @Return void
     */
    @Transactional
    @Override
    public void update(T t) {
        baseMapper.update(t);
    }

    /*
     * @Title: queryData
     * @Description: 高级查询
     * @Author: Aran
     * @Version: 1.0
     * @Date:  2022/6/26 14:54
     * @Parameters: [tQuery]
     * @Return cn.aran.basic.util.PageList<cn.aran.org.domain.T>
     */
    @Override
    public PageList<T> queryData(BaseQuery baseQuery) {
        Integer total = baseMapper.queryCount(baseQuery);
        List<T> rows = baseMapper.queryData(baseQuery);
        return new PageList<>(total, rows);
    }

    /*
     * @Title: batchRemove
     * @Description: 批量删除
     * @Author: Aran
     * @Version: 1.0
     * @Date:  2022/6/26 14:54
     * @Parameters: [ids]
     * @Return void
     */
    @Transactional
    @Override
    public void batchRemove(List<Long> ids) {
        baseMapper.batchRemove(ids);

    }
}
